\documentclass[11pt]{article}
\usepackage{amsthm,amsmath,amssymb}
% \usepackage{pdfsync}
% \usepackage{fancybox}

\def\xcolorversion{2.00}
\def\xkeyvalversion{1.8}

\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,snakes,automata,backgrounds,petri}
% \usepackage[latin1]{inputenc}

% Some useful commands:
\newcommand{\N}{\mathbb{N}} % The natural  numbers
\newcommand{\Z}{\mathbb{Z}} % The integer  numbers
\newcommand{\Q}{\mathbb{Q}} % The rational numbers
\newcommand{\R}{\mathbb{R}} % The real     numbers
\newcommand{\C}{\mathbb{C}} % The complex  numbers

% You can ignore all this...
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{propo}[thm]{Proposition}
\newtheorem{clm}[thm]{Claim}
\newtheorem{defn}[thm]{Definition}
\newtheorem{assm}[thm]{Assumption}
\newtheorem{rem}[thm]{Remark}
\newtheorem{egs}[thm]{Example}
\newtheorem{fct}[thm]{Fact}
\newtheorem{cons}[thm]{Construction}
\setlength{\fboxsep}{2pt}

\newenvironment{theorem}{\begin{thm}
% \begin{rm}
}{
% \end{rm}
\end{thm}}
\newenvironment{lemma}{\begin{lem}
% \begin{rm}
}{
% \end{rm}
\end{lem}}
\newenvironment{corollary}{\begin{cor}
% \begin{rm}
}{
% \end{rm}
\end{cor}}
\newenvironment{proposition}{\begin{propo}
% \begin{rm}
}{
% \end{rm}
\end{propo}}
\newenvironment{definition}{\begin{defn}\begin{rm}}%
{\end{rm}\end{defn}}
\newenvironment{assumption}{\begin{assm}\begin{em}}%
{\end{em}\end{assm}}
\newenvironment{claim}{\begin{clm}\begin{rm}}%
{\end{rm}\end{clm}}
\newenvironment{remark}{\begin{rem}\begin{em}}%
{\end{em}\end{rem}}
\newenvironment{example}{\begin{egs}\begin{em}}%
{\end{em}\end{egs}}
\newenvironment{fact}{\begin{fct}\begin{em}}%
{\end{em}\end{fct}}
\newenvironment{construction}{\begin{cons}\begin{em}}%
{~\qedsym\end{em}\end{cons}}

\newenvironment{bonaproblem}[2]{
 \begin{trivlist}
   \item[\hskip \labelsep \textsc{[B\'{o}na]} {\bfseries Chapter #1,
       Problem #2 :\ }]\it }
{\end{trivlist}}

\newenvironment{vlwproblem}[2]{
 \begin{trivlist}
   \item[\hskip \labelsep \textsc{[Van Lint \& Wilson]} {\bfseries Chapter #1,
       Problem #2 :\ }]\it }
{\end{trivlist}}

\pagestyle{empty}
\renewcommand{\c}{\checkmark}
\newcommand{\ps}{\textsf{P}}
%... up to here.


\title{Software Performance Lab Project, 2009}
\author{Sergey Karakovskiy}


\begin{document}
\maketitle
\begin{center}
\enlargethispage{2cm}
\mbox{}\vspace{-2cm}
% \line(1,0){360}\vspace{.5cm}

% \Large \textsc{AmiCo Manual}\vspace{.3cm}
\section{Contributions} % (fold)
\label{sec:contributions}

% section contributions (end)
I'm thinking about a file that describes what you added to the previously existing framework, the key contributions, and some form of evaluation, i.e. what works and does not work. Don't worry about the quality of the English/writing/formatting. Look at it as a way to convince me of the quality of your project.

 includes a brief motivation, a description of your design/approach with a rationale (why do it this way and not in a different way), and an evaluation of some form (e.g. show that the tool works on a small example, some info about the overhead, ...). You already have a doc about command line params (but only the params), and you could extend that (I'd also like how to use/run the tool, what I need to run it, e.g. what other libs or platforms). 
% \line(1,0){360}
\end{center}\vspace{-.3cm}
% \mbox{}\hfill {\scriptsize \it last edited \today}\\
\section{Getting Started} % (fold)
\label{sec:getting_started}
\subsection{General workflow and usage }\footnote{this weird section should be named more friendly} % (fold)
\label{sub:common}

% subsection mac_os_x (end)
\subsubsection{Java Calls Python} % (fold)
\label{sub:java_calls_python}
\begin{enumerate}
	\item \texttt{unzip} the archive \texttt{AmiCoDemo.zip}
	\item Create file \texttt{JavaCallsPython.py} in the root of the project. It's a simple Python file. Any user code, any library code, compatible with you current Python environment is valid.
	\item Create a native caller method like in \\ \texttt{ch/idsia/amico/javacallspython/JavaCallsPython.java}: 
	\begin{verbatim}
	    	private native int mean(int a, int b); 		
	\end{verbatim}
	This means that this method is going to be method implemented using C/C++; 
	\item \texttt{javac6 ch/idsia/amico/javacallspython/JavaCallsPython.java}. This will produce \texttt{JavaCallsPython.class} in the same directory with the \texttt{JavaCallsPython.java} file.
	\item \texttt{javah6 -jni ch.idsia.amico.javacallspython.JavaCallsPython} will produce	 \texttt{ch\_idsia\_amico\_javacallspython\_JavaCallsPython.h} header for C/C++ \footnote{I'll stick to C++ and all comments will be regarding C++} in the project root directory (in this example on the same level with directory \texttt{ch}).
	\item Create an implementation \texttt{JavaCallsPython.cc} file and implement the native method for Java using a Python module \texttt{JavaCallsPython.py} created before. This file should contain includes of the \texttt{jni.h}, \\  \texttt{ch\_idsia\_amico\_javacallspython\_JavaCallsPython.h}, \texttt{Python/Python.h} headers and the implementation of the \texttt{mean} method.
\begin{verbatim}
	Py_Initialize();
	std::cout << "\nC++: Loading python stuff: ";
	PyObject* main_module = PyImport_ImportModule("JavaCallsPython");
	if (main_module == 0)
	    std::cout << "\nC++: Main module had not been loaded";
	PyObject* res = PyObject_CallMethod(main_module, "computeMean", "(ii)", a, b);
	long result = PyInt_AsLong(res) ;
	return result;
\end{verbatim}
\item Build \& Run! You might would like to create a shell-script like this:
\begin{verbatim}
	javac ch/idsia/amico/javacallspython/JavaCallsPython.java
	javah -jni ch.idsia.amico.javacallspython.JavaCallsPython
	g++ -dynamiclib -framework Python 
	 -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers 
	 ch_idsia_amico_javacallspython_JavaCallsPython.cc
	 -o libAmiCo.dylib # this should be in one line;
	java -Djava.library.path=. ch.idsia.amico.javacallspython.JavaCallsPython
\end{verbatim}
\end{enumerate}
% subsection java_calls_python (end)

\subsubsection{Python Calls Java} % (fold)
\label{sub:python_calls_java}
It is a bit more tricky. Here we have to create a \texttt{JVM} in \texttt{C++} code and create a library that exports that \texttt{JVM} for the external world. 
\begin{enumerate}
	\item Create a normal \texttt{Java} program to be called:
	\begin{verbatim}
		public class PythonCallsJava
		{
		    public static void main(String[] args)
		    {
		        if (args.length < 1)
		        System.out.println("Hello World without args!");
		        else
		        System.out.println("Hello World " + args[0]);
		    }

		    public int fitness(int a, int b)
		    {
		        return a > b ? 42 : -21;
		    }

		    public int sumOfThree(int a, int b, int c)
			{
				return a + b + c;
			}
		}
	\end{verbatim}
	\item \texttt{javac PythonCallsJava.java} will produce the corresponding class file.
	\item Create a C++ \texttt{PythonCallsJava.cc} file containing code for the creation of the \texttt{JVM}  
	\begin{verbatim}
		JNIEnv *env;
	    JavaVM *jvm; 
	    jint res; 
	    jclass cls; 
	    jmethodID mid; 
	    jstring jst r; 
	    jclass stringClass; 
	    jobjectArray args; 

	    JavaVMInitArgs vm_args; 
	    JavaVMOption options[1]; 
	    options[0].optionString = "-Djava.class.path=."; //USER_CLASSPATH; 
	    vm_args.version = 0x00010004; 
	    vm_args.options = options; 
	    vm_args.nOptions = 1; 
	    vm_args.ignoreUnrecognized = JNI_FALSE; 
	    /* Create the Java VM */ 

	    std::cout << "Trying to create a VM...";
	    res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

		if (res < 0)
		{ 
	        fprintf(stderr, "Can't create Java VM\n"); 
	        return 1; 
	    } 
	\end{verbatim}
	and find and create the class containing required methods:
	\begin{verbatim}
	    cls = (env)->FindClass("PythonCallsJava"); 
	    if (cls == NULL) 
		{ 
			fprintf(stderr, "Can't find class \n"); 
	        goto destroy; 
		}		
	\end{verbatim}	
After that you can invoke methods :
\begin{verbatim}
	mid = (env)->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V"); 
    if (mid == NULL) 
	{ 
		fprintf(stderr, "Can't find method \n"); 
        goto destroy; 
    } 
    jstr = (env)->NewStringUTF(" from C!"); 
    if (jstr == NULL) 
	{ 
        goto destroy; 
    } 
    stringClass = (env)->FindClass("java/lang/String"); 
    args = (env)->NewObjectArray(1, stringClass, jstr); 
    if (args == NULL) 
	{ 
		fprintf(stderr, "Can't create args = (env)->NewObjectArray(env, 1, stringClass, jstr); \n"); 
        goto destroy; 
    } 
    (env)->CallStaticVoidMethod(cls, mid, args); 
	std::cout << "Trying to invoke <fitness>\n";
	mid = (env)->GetMethodID(cls, "fitness", "(II)I");
	if (mid == NULL) 
	{ 
		fprintf(stderr, "Can't find method <fitness>\n"); 
	        goto destroy; 
    } 
	std::cout << "\nC++: Allocating object:";
	jobject obj = (env)->AllocObject(cls);
	std::cout << "\nC++: Invokation...";
	jint fit = (env)->CallIntMethod(obj, mid, argc, b);
	std::cout << "\nC++: Fitness obtained " << fit;  
	return fit;
\end{verbatim}
And to complete the method put the code for the exceptional cases and destruction of the \texttt{JVM}:
\begin{verbatim}
	destroy: 
	    if ((env)->ExceptionOccurred()) 
		{ 
	        (env)->ExceptionDescribe(); 
	    } 
	    (jvm)->DestroyJavaVM(); 
		return 0;
\end{verbatim}
\item The tuff part has been done! Now create the Python script \texttt{PythonCallsJava.py} which will call the method from the \texttt{AmiCo} lib.
\begin{verbatim}
	import ctypes
	from ctypes.util import find_library

	def main():
		"""docstring for main"""
		print "library found: ", find_library("AmiCo")
		libc = ctypes.CDLL( 'libAmiCo.dylib' )   # 
		print 
		a = 5
		b = 3
		print "Py: calling to fitness with parameters: %d, %d " % (a, b)
		fitness = libc.main(a, b)  
		print 
		print "Py: Fitness = ", fitness

	if __name__ == '__main__':
		main()
	else:
		"module is imported";
\end{verbatim}

\item A shell script \texttt{run.sh} that builds and runs this demo looks like this:
\begin{verbatim}
    javac PythonCallsJava.java
    g++ -dynamiclib -framework JavaVM 
     -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers
     PythonCallsJava.cc -o libAmiCo.dylib # on a single line
    python PythonCallsJava.py
\end{verbatim}
\end{enumerate}

% subsubsection python_calls_java (end)
\subsection{Linux!!} % (fold)
\subsubsection{Java Calls Python} % (fold)
\label{ssub:java_calls_python}

% subsubsection java_calls_python (end)
\subsubsection{Python Calls Java} % (fold)
\label{ssub:python_calls_java}

% subsubsection python_calls_java (end)
\label{sub:linux}

% subsection linux (end)
\subsection{Windows} % (fold)
\label{sub:windows}
\subsubsection{Java Calls Python} % (fold)
\label{ssub:java_calls_python}

% subsubsection java_calls_python (end)
\subsubsection{Python Calls Java} % (fold)
\label{ssub:python_calls_java}

\subsection{Platform Specific Points} % (fold)
\label{sub:platform_specific_points}

% subsection common (end)
\subsubsection{MAC OS X} % (fold)
\label{sub:mac_os_x}

% subsection platform_specific_points (end)

% subsubsection python_calls_java (end)
% subsection windows (end)

% section getting_started (end)



% \noindent {\bf :} Nikos Mutsanas % <--- Write YOUR name here!
% \vspace{.3cm}\\
% %\line(1,0){360}\\
% \noindent {\it This portfolio contains complete $\c$ or partial \ps\ solutions for the following problems:}\\[2ex]
% %%% BEGIN
% \noindent 
% \textsc{[B\'{o}na]}: {\bf A Walk Through Combinatorics (2nd Ed.)}\\[1ex]
% % Add a \c under the exercise that you worked on, like in the example
% \begin{tabular}{||c|c|c||c|c|c||c|c|c|c||c|c|c||c|c||}
% \hline
% \multicolumn{3}{||c||}{Chapter 3} &
% \multicolumn{3}{ |c||}{Chapter 1} &
% \multicolumn{4}{ |c||}{Chapter 2} &
% \multicolumn{3}{ |c||}{Chapter 4} &
% \multicolumn{2}{ |c||}{Chapter 7}\\\hline
%  28 & 31 & 34 & 16 & 21 & 22 & 17 & 22 & 28 & 31 & 28 & 35 & 48 & 15 & 19\\\hline
%  \c &    &    &    &    &    &    &    &    &    &    &    &    &    &  \\\hline
% \end{tabular}
% \vspace{.7cm}\\
% \noindent \textsc{[Van Lint \& Wilson]}: {\bf A Course in Combinatorics (2nd Ed.)}\\[1ex]
% \begin{tabular}{||c|c|c||c|c|c|c||}
% \hline
% \multicolumn{3}{||c||}{Chapter 1} &
% \multicolumn{4}{ |c||}{Chapter 2} \\\hline 
% 1B  & 1E & 1F & 2D(1) & 2D(2) & 2E & 2F \\\hline
% \ps &    &    &       &       &    &    \\\hline
% \end{tabular}
% 
% %%% END
% 
% \newpage
% 
% % Typeset the problems from Bona and your solution as in the example:
% % The first number is the chapter, the second the exercise
% \begin{bonaproblem}{x}{y}
% %fill in the problem statement here
% Let~$G$ be a simple graph. Show that $G$ is simple.
% \end{bonaproblem}
% 
% \begin{proof}%[Solution.]  %% if you are answering a "Prove..." question,
%                            %% then leave as is.  If you are answering a 
%                            %% "How many..." or "Find..." question, then
%                            %% uncomment "%[Solution.]  (See the example below.)
% Proof by hand-waving.
% \end{proof}
% 
% % Typeset the problems from van Lint & Wilson and your solution as in
% % the example: The first number is the chapter, the second the
% % exercise
% \begin{vlwproblem}{x}{y}
% Let~$G$ be a connected graph. Show that $G$ is connected.
% \end{vlwproblem}
% 
% \begin{proof}%[Solution.]
% See previous proof.
% \end{proof}
% 
% %% Here are some complete solutions.
% \begin{vlwproblem}{yy}{xx}
% \textrm{(This example is not really from Van Lint and Wilson.)}
% Let~$G$ be a simple graph.  Prove that~$G$ is bipartite iff for every
% subgraph~$H$ of~$G$ it holds that $$\alpha(H) \geq |V(H)|/2.$$
% \end{vlwproblem}
% 
% We recall that~$\alpha(H)$ is the size of a maximal independent set of
% vertices in a graph.\\
% 
% \begin{proof}
%   First, assume that~$G$ is bipartite with bipartition~$(S,T)$, and
%   let~$H$ be an arbitrary subgraph.  By the pigeonhole principle, at
%   least half of the vertices of~$H$ are contained in either~$S$ or
%   $T$, and these vertices constitute an independent set.  (Clearly
%   $S$~and~$T$ are independent sets, and any subset of either will also
%   be independent.)  Hence $\alpha(H) \geq |V(H)|/2$.\\
% 
%   Now, assume that $\forall H \subseteq G$ we have $\alpha(H) \geq
%   |V(H)|/2$.  Assume for the moment that~$G$ is not bipartite.
%   Then~$G$ contains an odd-length cycle~$C$; say its length is
%   $n=2k+1$ for some~$k \geq 1$.  Since~$C$ is a subgraph of~$G$ it
%   must be the case that $\alpha(C) \geq (2k+1)/2 = k + 1/2$, and since
%   $\alpha(C)$ is an integer this implies that~$C$ contains an
%   independent set of size at least $k+1 > n/2$.  But (by pigeonhole)
%   taking more than half of the vertices of~$C$ will force the
%   selection of some two vertices that are adjacent. Thus we have a
%   contradiction, and so~$G$ must be bipartite.
% \end{proof}
% 
% \begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto]
% 
%   \tikzstyle{place}=[circle,thick,draw=blue!75,fill=blue!20,minimum size=6mm]
%   \tikzstyle{red place}=[place,draw=red!75,fill=red!20]
%   \tikzstyle{transition}=[rectangle,thick,draw=black!75,
%   			  fill=black!20,minimum size=4mm]
% 
%   \tikzstyle{every label}=[red]
% 
%   \begin{scope}
%     % First net
%     \node [place,tokens=1] (w1)                                    {};
%     \node [place] (c1) [below of=w1]                      {};
%     \node [place] (s)  [below of=c1,label=above:$s\le 3$] {};
%     \node [place] (c2) [below of=s]                       {};
%     \node [place,tokens=1] (w2) [below of=c2]                      {};
% 
%     \node [transition] (e1) [left of=c1] {}
%       edge [pre,bend left]                  (w1)
%       edge [post,bend right]                (s)
%       edge [post]                           (c1);
% 
%     \node [transition] (e2) [left of=c2] {}
%       edge [pre,bend right]                 (w2)
%       edge [post,bend left]                 (s)
%       edge [post]                           (c2);
% 
%     \node [transition] (l1) [right of=c1] {}
%       edge [pre]                            (c1)
%       edge [pre,bend left]                  (s)
%       edge [post,bend right] node[swap] {2} (w1);
% 
%     \node [transition] (l2) [right of=c2] {}
%       edge [pre]                            (c2)
%       edge [pre,bend right]                 (s)
%       edge [post,bend left]  node {2}       (w2);
%   \end{scope}
% 
%   \begin{scope}[xshift=6cm]
%     % Second net
%     \node [place,tokens=1]
%                       (w1')                                                {};
%     \node [place]     (c1') [below of=w1']                                 {};
%     \node [red place] (s1') [below of=c1',xshift=-5mm,label=left:$s$]      {};
%     \node [red place,tokens=3]
%                       (s2') [below of=c1',xshift=5mm,label=right:$\bar s$] {};
%     \node [place]     (c2') [below of=s1',xshift=5mm]                      {};
%     \node [place,tokens=1]
%                       (w2') [below of=c2']                                 {};
% 
%     \node [transition] (e1') [left of=c1'] {}
%       edge [pre,bend left]                  (w1')
%       edge [post]                           (s1')
%       edge [pre]                            (s2')
%       edge [post]                           (c1');
% 
%     \node [transition] (e2') [left of=c2'] {}
%       edge [pre,bend right]                 (w2')
%       edge [post]                           (s1')
%       edge [pre]                            (s2')
%       edge [post]                           (c2');
% 
%     \node [transition] (l1') [right of=c1'] {}
%       edge [pre]                            (c1')
%       edge [pre]                            (s1')
%       edge [post]                           (s2')
%       edge [post,bend right] node[swap] {2} (w1');
% 
%     \node [transition] (l2') [right of=c2'] {}
%       edge [pre]                            (c2')
%       edge [pre]                            (s1')
%       edge [post]                           (s2')
%       edge [post,bend left]  node {2}       (w2');
%   \end{scope}
% 
%   \draw [-to,thick,snake=snake,segment amplitude=.4mm,
%          segment length=2mm,line after snake=1mm]
%     ([xshift=5mm]s -| l1) -- ([xshift=-5mm]s1' -| e1')
%     node [above=1mm,midway,text width=3cm,text centered]
%       {replacement of the \textcolor{red}{capacity} by 
%         \textcolor{red}{two places}};
% 
%   \begin{pgfonlayer}{background}
%     \filldraw [line width=4mm,join=round,black!10]
%       (w1.north  -| l1.east)  rectangle (w2.south  -| e1.west)
%       (w1'.north -| l1'.east) rectangle (w2'.south -| e1'.west);
%   \end{pgfonlayer}
% \end{tikzpicture}
% 
% 
% \begin{bonaproblem}{yy}{xx}
%   An employee wants to work five days in a week, but also wants to
%   have at least one of Saturday and Sunday off.  In how many ways can
%   he choose the days she will work?
% \end{bonaproblem}
% 
% \begin{proof}[Solution.]
%   We will give two methods of solution.  First, we count the number of
%   ``bad'' schedules.  If the employee is forced to work on both
%   Saturday and Sunday, then three additional days must be chosen from
%   the remaining five days of the week.  Thus the number of ``good''
%   schedules is
% \[
% {7 \choose 5} - {5 \choose 3} = {7 \choose 2} - {5 \choose 2} = 11 \;.
% \]
% An alternative solution is obtained as follows.  We consider the
% ``good'' schedules in cases.
% \begin{itemize}
% \item Case 1: the employee works on Saturday and not Sunday.  In this
%   case we must select four work days from the remaining five days
%   (M-F), so there are ${5 \choose 4} = {5 \choose 1} = 5$ schedules.
% \item Case 2: the employee works Sunday but not Saturday.  Again here
%   we have ${5 \choose 4}=5$ schedules.
% \item Case 3: the employee does not work on Saturday or Sunday.  Here
%   there is clearly only one schedule.
% \end{itemize}
% Adding together our disjoint cases, we see again that there are 11
% good schedules.
% \end{proof}
% 
\end{document}
